package team.kirohuji;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.apache.shiro.subject.Subject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.data.mongo.MongoDataAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import team.kirohuji.utils.ResponseBean;

@Controller
@SpringBootApplication(exclude = {MongoDataAutoConfiguration.class })
@ComponentScan("team.kirohuji")
public class Application {
	
	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);

	}
	
	@RequestMapping("/article/test")
	@ResponseBody
    public ResponseBean article() {
        Subject subject = SecurityUtils.getSubject();
        if (subject.isAuthenticated()) {
            return new ResponseBean(200, "You are already logged in", null);
        } else {
            return new ResponseBean(200, "You are guest", null);
        }
    }
	
	@RequestMapping("/require_auth/test")
    @RequiresAuthentication
    @ResponseBody
    public ResponseBean requireAuth() {
        return new ResponseBean(200, "You are authenticated", null);
    }
	@RequestMapping("/test")
	@RequiresRoles({"admin"})
    @ResponseBody
    public ResponseBean test() {
        return new ResponseBean(200, "You are authenticated", null);
    }
}